package com.example.hsh.homefragment.view;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.ColorRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by HSH on 2016/12/22.
 */

public class RecyclerViewLoadMoreUtil extends RecyclerView.OnScrollListener {
    private RecyclerView recyclerView;
    private View footer;
    private int color;
    private Context mContext;
    private final float density;

    public RecyclerViewLoadMoreUtil(Context context) {
        mContext = context;
        density = context.getResources().getDisplayMetrics().density;
    }

    public void setAnchor(RecyclerView recyclerView) {
        this.recyclerView = recyclerView;
    }

    public void addFooter(View footer) {
        this.footer = footer;
    }

    public void setColor(@ColorRes int color) {
        this.color = color;
    }

    public void build(){
        recyclerView.addOnScrollListener(this);
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        RecyclerView.Adapter adapter = recyclerView.getAdapter();
    }

    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
    }

    class RecyclerViewFooter extends RecyclerView.ItemDecoration{

        private final Paint paint;

        public RecyclerViewFooter(@ColorRes int color) {
            paint = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint.setColor(ContextCompat.getColor(mContext, color));
            paint.setStrokeWidth(density * 3);
        }

        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDraw(c, parent, state);
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
        }
    }
}
